//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    imgUrls: [],
    listCompany: [], //个人
    listenterprise: [], // 企业
    searchinput: '',
    companysub: [],
    type: 0,
    bigImg: '',
    // 校友风采搬过来的
    dataList: null,
  },
  showBigImg: function(e) {
    this.setData({
      bigImg: e.currentTarget.dataset.src
    })
  },
  hideBigimg: function() {
    this.setData({
      bigImg: ''
    })
  },

  //获取轮播图数据
  getSwiperArr() {
    let _this = this;
    app.util.ajax({
      url: 'index/banner',
      success: ((res) => {
        _this.setData({
          imgUrls: res
        })
      })
    }, )
  },
  //搜索
  toSearch() {
    wx.navigateTo({
      url: "/pages/index/Search/Search"
    });
  },
  toNearby() {
    wx.navigateTo({
      url: "/pages/index/nearby/nearby"
    });
  },

  // 个人、企业列表
  listData() {
    let _this = this;
    app.util.ajax({
      url: 'index/index',
      data: {
        user_id: app.globalData.userInfo.user_id
      },
      success: function(res) {
        _this.setData({
          listCompany: res.company,
          listenterprise: res.enterprise
        })
      }
    })
  },

  //关注
  follow(e) {
    let _this = this;
    let user_id = app.globalData.userInfo.user_id;
    let type = e.currentTarget.dataset.type;
    let member_id = e.currentTarget.dataset.member_id;
    let status = e.currentTarget.dataset.status == '1' ? 0 : 1;
    app.util.ajax({
      url: 'index/follow',
      data: {
        user_id: user_id,
        com_state: type,
        member_id: member_id,
        state: status,
      },
      success: function(res) {
        _this.listData();
      }
    })
  },
  //宣传活动
  getactivity: function(e) {
    wx.navigateTo({
      url: '/pages/index/Publicity_campaign/Publicity_campaign'
    })
  },
  //平台中心
  getvisit: function(e) {
    wx.navigateTo({
      url: '/pages/index/platform_activities/platform_activities'
    })
  },
  //信息发布
  getrelease: function(e) {
    wx.navigateTo({
      url: '/pages/index/Information_delivery/Information_delivery'
    })
  },
  //企业风采
  getcompany: function(e) {
    wx.navigateTo({
      url: '/pages/index/corporate_style/corporate_style'
    })
  },
  getenterprise: function(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/listMsg/listMsg?type=1&id=' + id
    })
  },
  tapenterprise: function(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/listMsg/listMsg?type=2&id=' + id
    })
  },
  get: function(e) {
    wx.navigateTo({
      url: 'pages/index/enterprise/enterprise'
    })
  },
  onLoad: function() {

  },
  onShow: function() {
    if (!app.globalData.userInfo) {
      wx.showModal({
        content: '请前往登录',
        showCancel: false,
        success: function(res) {
          if (res.confirm) {
            wx.switchTab({
              url: "/pages/user/user"
            })
          }
        }
      })
      return;
    }
    this.getSwiperArr();
    // this.listData();
    this.getCompanyList();
  },
  // 分享
  onShareAppMessage(res) {
    return {
      title: '广州大学校友会校友企业家专委会',
      path: '/pages/index/index'
    }
  },

  // 校友风采搬过来的
  getCompanyList: function () {
    let _this = this;
    let user_id = app.globalData.userInfo.user_id;
    app.util.ajax({
      url: 'EnterpriseMien/index',
      data: {
        user_id: user_id
      },
      success: function (data) {
        _this.setData({
          dataList: data.data
        })
      }
    })
  },
  // 是否点赞
  isPraise: function (e) {
    let itemId = e.currentTarget.dataset.id,
      state = e.currentTarget.dataset.state ? 0 : 1,
      _this = this;
    app.util.ajax({
      url: 'EnterpriseMien/zambia',
      data: {
        id: itemId,
        user_id: app.globalData.userInfo.user_id,
        state: state
      },
      success: function (data) {
        _this.getCompanyList();
      }
    })
  },
  // 详情
  seeCompanyCard: function (e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/corporate_style/corporate_styleDetail/corporate_styleDetail?id=' + id
    })
  },
  seeComment: function (e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/index/corporate_style/corporate_styleDetail/corporate_styleDetail?id=' + id + '&comment=comment'
    })
  },
  bannerDetails (e) {
    let id = e.currentTarget.dataset.id;
    console.log(id)
    wx.navigateTo({
      url: '/pages/news/newsDetails/newsDetails?id=' + id
    })
  }
})